package com.shop2cn.iapi.shenqisettlement.testcase;

import com.shop2cn.iapi.shenqisettlement.parameter.MerchantSaveConfirmPaymentInfoReq;
import com.shop2cn.iapi.shenqisettlement.service.MerchantSaveConfirmPaymentInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.shenqisettlement.DistributorAgencyOfflineMonthBill;
import com.ymttest.database.sqlwapper.shenqisettlement.DistributorAgencyOfflineMonthBillWrapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

import org.junit.*;
import org.junit.experimental.categories.Category;

/**
 * 根据国家获取汇率 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_MerchantSaveConfirmPaymentInfo {

	private static MerchantSaveConfirmPaymentInfoReq merchantSaveConfirmPaymentInfoReq;
	private static MerchantSaveConfirmPaymentInfoCall merchantSaveConfirmPaymentInfoCall;

	private DistributorAgencyOfflineMonthBillWrapper distributorAgencyOfflineMonthBillWrapper = new DistributorAgencyOfflineMonthBillWrapper();

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("上传支付凭证-线下结算");
	}

	@Before
	public void caseUp() {
		merchantSaveConfirmPaymentInfoReq = new MerchantSaveConfirmPaymentInfoReq();
		merchantSaveConfirmPaymentInfoCall = new MerchantSaveConfirmPaymentInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(merchantSaveConfirmPaymentInfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	public void verify() {

		DistributorAgencyOfflineMonthBill actualObject = distributorAgencyOfflineMonthBillWrapper
				.selectByPrimaryKey(merchantSaveConfirmPaymentInfoReq
						.getBillId());

		Logger.verifyEquals(
				merchantSaveConfirmPaymentInfoReq.getDistributorId(),
				actualObject.getDistributor_id(), "验证Distributor_id");
		Logger.verifyEquals(String.valueOf(merchantSaveConfirmPaymentInfoReq
				.getOperatorId()), actualObject.getPaid_operator(),
				"验证Paid_operator");
		DataUtil.verifyDateEquals(
				merchantSaveConfirmPaymentInfoReq.getPaidTime(),
				actualObject.getPaid_time(), "验证Paid_time");
		Logger.verifyEquals(merchantSaveConfirmPaymentInfoReq.getVoucherUrl(),
				actualObject.getPaid_voucher(), "验证Paid_voucher");
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_MerchantSaveConfirmPaymentInfo_001() {
		Logger.start(true, "上传支付凭证成功");
		try {

			distributorAgencyOfflineMonthBillWrapper.updatePaid(3L, 0);

			merchantSaveConfirmPaymentInfoReq.setMerchantId(4321L);
			merchantSaveConfirmPaymentInfoReq.setDistributorId(501565934L);
			merchantSaveConfirmPaymentInfoReq.setOperatorId(1L);
			merchantSaveConfirmPaymentInfoReq.setPaidTime(YMTDateUtil
					.getBeforeOrNextHour(-1, YMTDateUtil.YMDHMSS));
			merchantSaveConfirmPaymentInfoReq.setBillId(3L);
			merchantSaveConfirmPaymentInfoReq.setVoucherUrl(TestDataManager
					.randomStr(5));

			merchantSaveConfirmPaymentInfoCall
					.setData(merchantSaveConfirmPaymentInfoReq);
			merchantSaveConfirmPaymentInfoCall.callService();

			this.verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_MerchantSaveConfirmPaymentInfo_002() {
		Logger.start(true, "账单不存在，上传失败");
		try {

			merchantSaveConfirmPaymentInfoReq.setMerchantId(4321L);
			merchantSaveConfirmPaymentInfoReq.setDistributorId(1234L);
			merchantSaveConfirmPaymentInfoReq.setOperatorId(1L);
			merchantSaveConfirmPaymentInfoReq.setPaidTime(YMTDateUtil
					.getBeforeOrNextHour(-1, YMTDateUtil.YMDHMSS));
			merchantSaveConfirmPaymentInfoReq.setBillId(2L);
			merchantSaveConfirmPaymentInfoReq.setVoucherUrl(TestDataManager
					.randomStr(5));

			merchantSaveConfirmPaymentInfoCall
					.setData(merchantSaveConfirmPaymentInfoReq);
			merchantSaveConfirmPaymentInfoCall.callService();

			Logger.verifyEquals("账单不存在，无需支付",
					merchantSaveConfirmPaymentInfoCall.getMsg(), "验证msg");
			Logger.verifyEquals(3,
					merchantSaveConfirmPaymentInfoCall.getErrorCode(),
					"验证resultCode");
			Logger.verifyEquals(false,
					merchantSaveConfirmPaymentInfoCall.getSuccess(),
					"验证success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_MerchantSaveConfirmPaymentInfo_003() {
		Logger.start(true, "已经上传支付凭证的账单，再次上传，上传失败");
		try {

			merchantSaveConfirmPaymentInfoReq.setMerchantId(4321L);
			merchantSaveConfirmPaymentInfoReq.setDistributorId(1234L);
			merchantSaveConfirmPaymentInfoReq.setOperatorId(1L);
			merchantSaveConfirmPaymentInfoReq.setPaidTime(YMTDateUtil
					.getBeforeOrNextHour(-1, YMTDateUtil.YMDHMSS));
			merchantSaveConfirmPaymentInfoReq.setBillId(3L);
			merchantSaveConfirmPaymentInfoReq.setVoucherUrl(TestDataManager
					.randomStr(5));

			merchantSaveConfirmPaymentInfoCall
					.setData(merchantSaveConfirmPaymentInfoReq);
			merchantSaveConfirmPaymentInfoCall.callService();

			Logger.verifyEquals("该月账单已经支付，请不重复支付",
					merchantSaveConfirmPaymentInfoCall.getMsg(), "验证msg");
			Logger.verifyEquals(3,
					merchantSaveConfirmPaymentInfoCall.getErrorCode(),
					"验证resultCode");
			Logger.verifyEquals(false,
					merchantSaveConfirmPaymentInfoCall.getSuccess(),
					"验证success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}